#include <iostream>
#include <string>
using namespace std;

class Solution {
public:
    string minWindow(string s, string t)
    {
        char hash1[128] = { 0 };
        int kinds = 0;
        for (auto& ch : t)
            if (hash1[ch]++ == 0)
                ++kinds;

        char hash2[128] = { 0 };
        int begin = -1, minLen = INT_MAX;
        for (int left = 0, right = 0, count = 0; right < s.size(); ++right)
        {
            char in = s[right];
            if (++hash2[in] == hash1[in])
                ++count;
            while (count == kinds)
            {
                if (right - left + 1 < minLen)
                {
                    begin = left;
                    minLen = right - left + 1;
                }
                char out = s[left++];
                if (hash2[out]-- == hash1[out])
                    --count;
            }
        }
        if (begin == -1)
            return "";
        else
            return s.substr(begin, minLen);
    }
};

int main()
{
    Solution();

    return 0;
}